/** @jsxImportSource @emotion/react */
import * as React from "react";
import { OriginalViewProps, } from "../../common/base";
import {EntranceSetup, config设备概况, config观测数据,tail观测 } from "./orcBase";
import {createItem, } from "../../common/eHelper";
import {useRecordList} from "../../hook/useRecordList";
import {setupItemAreaRoute} from "./orcIspConfig";
import {EditStorageContext} from "../../StorageContext";
import {Text, useTheme} from "customize-easy-ui-component";
import {ItemInstrumentTable} from "../../common/Instrument";
import {SiteConditionSund,} from "../../elevator/sundryDj/editor";
import {GenCode} from "../../common/GenCode";
import {ActionMapItem} from "../../common/ActionMapItem";
import {config记录} from "./FormatOriginal";
import {MeasureCritMem} from "../../hook/useMeasure";
import {DeviceSurveyD} from "../../crane/editor";
import {WitnessSimple} from "../../elevator/stest/editor";
import {config检验复检表, RecheckEditor} from "../../common/editor";
import {ConclusionHydlic} from "../../lift/hydlicDj/editor";

//"sk":[{"no":"3.2.4.3","r":4,"s":1},{"pr":"*","r":3,"s":1}
const defFrameM={
    'Rec3ClRep2Cl': `{ "mg":2, "dcl":"A","cl":"A",
        "sk":[{"pr":"*","no":"3.2.5.3","r":0},{"pr":"*","r":0},{"pr":"*","r":3,"s":1},0
         ]
    }`,
};

export const tItems现场=[
    ['1、井道和机器空间内温度',{f:'T',
        N: <Text>1、机房或者机器设备间的空气温度保持在5℃～40℃之间；（单位：℃）</Text>},],
    ['2、供电电压波动范围',{f:'V',
        N: <Text>2、电源输入电压波动在额定电压值±7％的范围内；（单位：V ）</Text>},],
    ['3、封闭和防护警示',{f:'P',
        N: <Text>3、相关区域没有与电梯运行无关的物品和设备，进行了必要的封闭和防护，放置表明正在进行检验的警示标志；</Text>},],
    ['4、维保单位配合',{f:'W',
        N: <Text>4、维护保养单位安排了专业技术人员，配合检验人员实施现场检验。</Text>},],
];
const 备注选=["1、本报告第XX、XX、XX项的检验结果为不符合，使用单位已经承诺采取安全措施，对电梯实行监护使用(见编号为XXXXXX的《电梯检验意见通知书》)。",
    "2、本检验机构于XXXX年XX月XX日出具了编号为XXXXX的《杂物电梯定期检验报告》。按照TSG T7001—2023的规定，本检验机构对该报告所对应的电梯进行了复检，出具本检验报告。"
];
const 见证选=["1、整改见证资料名称《xxxx》，编号：" ];

const recordPrintList =[
    createItem('Entrance', <EntranceSetup/>),
    // createItem('FrontCover', <FrontCover/>),
    createItem('Instrument', <ItemInstrumentTable label={'一、主要检验仪器设备性能检查'} />),
    createItem('Survey', <DeviceSurveyD config={config设备概况} label={'二、设备概况'}/>),
    createItem('Item', null),
    createItem('ReCheck', <RecheckEditor config={config检验复检表} label={'四、检验不符合项目记录及复检结果'} setup={setupItemAreaRoute}/>),
    createItem('Conclusion', <ConclusionHydlic label={'五、检验结论'}/>),
    createItem('Witness', <WitnessSimple  label={'六、见证材料 七、备注'} titles={['六、见证材料','七、备注']} memolist={备注选} witlist={见证选}
                                         children={[null,
                             <React.Fragment key={12}>注：特殊情况，应在备注中说明检验人员所负责检验的项目编号。</React.Fragment>
                         ]}
                    />),
    createItem('Measure', <MeasureCritMem config={config观测数据}  label={'八、观测数据及测量结果记录'}>
        {tail观测}
    </MeasureCritMem>),
    createItem('SiteCondition', <SiteConditionSund config={tItems现场} label={'附录A：现场检验条件确认'}/>),
];
if(process.env.REACT_APP_TEST==='true')  recordPrintList.splice(0,0,createItem('GenCode', <GenCode type='Rec3ClRep2Cl' frameMod={defFrameM}/>));


export const OriginalView=
  React.forwardRef((
    { action,  verId, repId='', rep,}
    :OriginalViewProps, ref
  ) => {
    const context =React.useContext(EditStorageContext);
    if(context == null)    throw new Error("EditStorageContext没有提供");
    const {storage, } =context;
    const theme = useTheme();
    const recordPrintListNow =React.useMemo(() => {
      let routeAreas=[] as any[];
      const impressionismAs =setupItemAreaRoute({rep, orc:storage, theme});
      let extendTags =Reflect.ownKeys(impressionismAs) as string[];
      const oldItCount=recordPrintList.length;
      let prevpos=0;
      for(let p=0; p<oldItCount; p++){
        if(extendTags.indexOf(recordPrintList[p].itemArea)>=0){     //需要展开 扩充的标签
            routeAreas=routeAreas.concat(recordPrintList.slice(prevpos,p));
            const itemConfigs= impressionismAs?.[recordPrintList[p].itemArea];
            let seq = 0;
            let moreItems = [] as any;
            itemConfigs.forEach((area, x) => {
              seq += 1;
              const rowHead =<ActionMapItem key={seq} alone={false} editAreasConf={itemConfigs}
                                                    index={x} sureD editIts={config记录} />;
              moreItems.push(createItem(area.tag, rowHead));
            });
            routeAreas=routeAreas.concat(moreItems);
            prevpos=p+1;
        }
      }
      routeAreas=routeAreas.concat(recordPrintList.slice(prevpos));
      return routeAreas;
    }, [verId, repId,rep, storage?._Oitems, theme]);

    const {list}=useRecordList(ref,rep,recordPrintListNow,action,verId);
    return <React.Fragment>
      {list}
        {/*      <Button  intent="primary"
                   onPress={(e) => { handleSubmit!();
                   }}
          >送打印转换器
          </Button>*/}
    </React.Fragment>;
  } );
